package com.mygdx.game;

import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actions.Actions;
import com.badlogic.gdx.scenes.scene2d.actions.MoveByAction;
import com.badlogic.gdx.scenes.scene2d.actions.MoveToAction;
import com.badlogic.gdx.scenes.scene2d.actions.RepeatAction;
import com.badlogic.gdx.scenes.scene2d.actions.RotateByAction;
import com.badlogic.gdx.scenes.scene2d.actions.RotateToAction;
import com.badlogic.gdx.scenes.scene2d.actions.ScaleByAction;
import com.badlogic.gdx.scenes.scene2d.actions.ScaleToAction;
import com.badlogic.gdx.scenes.scene2d.actions.SequenceAction;

/**
 * Created by 80002023 on 2016/7/26.
 */
public class AnimationDemo extends ApplicationAdapter {
    private Stage mStage;

    @Override
    public void create() {
        mStage = new Stage();

        AnimationPlayer player = new AnimationPlayer();
        player.setPosition(800 / 2, 480 / 2);

        // 移动操作
        MoveByAction action1 = Actions.moveBy(150, 0, 3);
        ScaleByAction action2 = Actions.scaleBy(3, 3, 3);
        RotateByAction action3 = Actions.rotateBy(90, 3);

        // 还原操作
        ScaleToAction action4 = Actions.scaleTo(1, 1);
        RotateToAction action5 = Actions.rotateTo(0);
        MoveToAction action6 = Actions.moveTo(800 / 2, 480 / 2);

        // 顺序执行action
        SequenceAction sequenceAction = Actions.sequence(action1, action2,
                action3, action4, action5, action6);
        sequenceAction.setActor(player);

        // 无限循环三个动作
        RepeatAction epeatAction = Actions.repeat(RepeatAction.FOREVER,
                sequenceAction);

        player.addAction(epeatAction);

        mStage.addActor(player);
    }

    @Override
    public void render() {
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        mStage.act(Gdx.graphics.getDeltaTime());
        mStage.draw();
    }

    @Override
    public void dispose() {
        // 所有实现Disposable接口的都需要释放资源
        mStage.dispose();
    }
}
